package lambda.lambda_ideas.lambda_usage;

import lambda.lambda_ideas.base.Apple;
import lambda.lambda_ideas.lambda_thought.AppleFiltersWithLambdaThought;

import java.util.List;

/**
 * Description: 带有lambda的筛选器
 *
 * @author code-worker
 * @date 2021/10/03 10:53
 */
public class AppleFiltersWithLambda {
    public static void main(String[] args) {
        List<Apple> apples = Apple.initData();
        //使用自定义的筛选器
        System.out.println("green apple: "+ AppleFiltersWithLambdaThought.filterApples(apples, apple -> "green".equals(apple.getColor())));
        System.out.println("heavy apple: "+ AppleFiltersWithLambdaThought.filterApples(apples, apple -> apple.getWeight() > 150));
        //使用Java stream自带的筛选器
        System.out.println("green apple: "+ apples.stream().filter(apple->"green".equals(apple.getColor())));
        System.out.println("heavy apple: "+ apples.stream().filter(apple->apple.getWeight() > 150));
    }
}
